<?php

/*
 * Created on 2008-11-18
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
class CompanyGroupController extends AppController {
	var $name = 'CompanyGroup';

	var $uses = array (
		'CompanyGroup',
		'Company',
		'Job'
	);

	function index() {
		$id=$_GET['id'];
		if(empty($id)){
			$this->show404();
			exit();
		}else{
			$cg = $this->CompanyGroup->findAllById($id);
			$companys = $cg[0]['Company'];
			$jobsid = array ();
			for ($i = 0; $i < count($companys) ; $i++) {
				$companyId = $companys[$i]['id'];
				$jobsid[$i] = $companyId;
			}
			$sid = implode(',', $jobsid);
			$conditions = "\"Job\".\"company_id\" in ($sid) and " .
			"\"Job\".\"job_status_id\"=1 AND (\"Job\".\"public_start\"||' '||\"Job\".\"public_start_hour\"||':'||\"Job\".\"public_start_min\")<=to_char(now(),'YYYY-MM-DD HH24:MI') AND (\"Job\".\"public_end\"||' '||\"Job\".\"public_end_hour\"||':'||\"Job\".\"public_end_min\")>=to_char(now(),'YYYY-MM-DD HH24:MI')" .
			" AND \"Job\".\"public_close_date\" is NULL" .
			" AND \"Job\".\"deleted\" is NULL ";
			
			
			$order='Job.public_start desc,' .
				   'Job.public_start_hour desc,' .
				   'Job.public_start_min desc,' .
				   'Job.approve_date desc';
			$alljob = $this->Job->findAll($conditions,null,$order,$this->show,$this->page,2);
			$count = $this->Job->findCount($conditions);
			$pagestr=$this->initPageCount($count,'件','件','中',$this->show);
			$this->set('pagestr',$pagestr);
			$this->set('id',$id);
			$this->set('alljob',$alljob);
			$this->setPaging('ajax','/companyGroup?id='.$id,$count,$this->show,null,$this->show);
		}
		
	}
	
	function setPaging($style='ajax',$link,$count,$show=null,$page=null,$limit=null){
	 	$paging['style'] = $style;
		$paging['count']=$count;
		$paging['show'] = empty($show) ? array($this->show) : array($show);
		$paging['link'] = $link.'&page=';	
		$paging['page'] = empty($page) ? $this->page : $page;
		$paging['limit'] = empty($limit) ? $this->show : $limit;
		$paging['show_select'] = $this->pageShowSelect();
		$this->set('paging',$paging);
	 }
}
?>
